package classdemo;

import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @DESCRIPATION
 * @AUTHOR 戴超
 * @DATE 2018/6/19
 **/
public class SocketTest {

    public static void main(String[] args) throws Exception{
        Socket client = null; //  声明Socket 对象
        client = new Socket("localhost", 8888); //  指定连接的主机和端口
        BufferedReader buf = null; //  声明BufferedReader 对象, 接收信息
        buf = new BufferedReader(
                new InputStreamReader(
                        client.getInputStream()));//  取得客户端的输入流
        String str = buf.readLine(); //  读取信息
        System.out.println(" 服务器端输出内容：" + str);
        client.close(); //  关闭Socket
        buf.close();
    }
}
